<template>
  <div class="wrapper">
    <swiper :options="swiperOption" v-if="showSwiper">
      <!-- slides -->
      <swiper-slide v-for="item of list" :key="item.id">
        <img class="swiper-img" :src="item.imgUrl" alt="">
      </swiper-slide>
      <!-- Optional controls -->
      <div class="swiper-pagination"  slot="pagination"></div>
      <!--<div class="swiper-button-prev" slot="button-prev"></div>-->
      <!--<div class="swiper-button-next" slot="button-next"></div>-->
      <!--<div class="swiper-scrollbar"   slot="scrollbar"></div>-->
    </swiper>
  </div>
</template>
<!--swiperOption 返回一个空对象-->
<!--swiperList 通过数组循环输出swiper-slide,遍历swiperList，做一个循环-->
<!--:key="item.id"  保证循环代码的key值-->
<!--loop: true 支持循环轮播-->
<script>
export default {
  name: 'HomeSwiper',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        loop: true
      }
      // swiperList: [
      //   {
      //     id: '0001',
      //     imgUrl: require('images/banner.jpg')
      //   },
      //   {
      //     id: '0002',
      //     imgUrl: require('images/index_bg.jpg')
      //   },
      //   {
      //     id: '0003',
      //     imgUrl: require('images/banner.jpg')
      //   }
      // ]
    }
  },
  computed: {
    showSwiper () {
      return this.list.length
    }
  }
}
</script>
<!-- >>> 样式进行穿透-->
<style lang="stylus" scoped>
  .wrapper >>> .swiper-pagination-bullet-active
    background: #fff
  .wrapper
    .swiper-img
      width: 100%
      object-fit cover
      height 2.76rem
</style>
